/*
 * 封装localStorage获取数据、存储数据、删除数据的方法
 */

/*
 * 获取本地localStorage数据
 */
export const getLocalStorageItem = itemNameStr => {
  const data = window.localStorage.getItem(itemNameStr)
  try {
    return JSON.parse(data)
  } catch (err) {
    return data
  }
}

/*
 * 将数据存储到localStorage
 */
export const setLocalStorageItem = (itemNameStr, itemData) => {
  if (typeof itemData === 'object') {
    itemData = JSON.stringify(itemData)
  }
  window.localStorage.setItem(itemNameStr, itemData)
}

/*
 * 删除localStorage中的数据
 */
export const removeLocalStorageItem = itemNameStr => {
  window.localStorage.removeItem(itemNameStr)
}
